package android.zhcs.myapplication;

import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws UiObjectNotFoundException, InterruptedException {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertEquals("android.zhcs.myapplication", appContext.getPackageName());
        Instrumentation i = InstrumentationRegistry.getInstrumentation();
        UiDevice uiDevice = UiDevice.getInstance(i);
        uiDevice.swipe(0,2000,0,700,10);
        UiObject object = uiDevice.findObject(new UiSelector().resourceId("com.google.android.apps.nexuslauncher:id/apps_list_view"));
        object.swipeUp(50);
        Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
        Intent intent = context.getPackageManager().getLaunchIntentForPackage("android.zhcs.myapplication");
        context.startActivity(intent);
        Thread.sleep(500);
        uiDevice.findObject(new UiSelector().resourceId("android.zhcs.myapplication:id/xz1")).click();
        Thread.sleep(500);
        uiDevice.findObject(new UiSelector().textContains("大桌")).click();
        Thread.sleep(500);
        uiDevice.findObject(new UiSelector().resourceId("android.zhcs.myapplication:id/xz2")).click();
        Thread.sleep(500);
        uiDevice.findObject(new UiSelector().textContains("2024/5/30")).click();
        Thread.sleep(500);
        uiDevice.findObject(new UiSelector().resourceId("android.zhcs.myapplication:id/xz3")).click();
        Thread.sleep(500);
        uiDevice.findObject(new UiSelector().textContains("8:00-10:00")).click();
        Thread.sleep(500);
        uiDevice.findObject(new UiSelector().textContains("确认")).click();
        Thread.sleep(500);
        Thread.sleep(500);
        Thread.sleep(500);
        uiDevice.pressBack();
        uiDevice.pressBack();
        uiDevice.pressBack();
    }
}